package com.yuyi.full;

import java.io.Serializable;

import com.atung.exceptiom.LcExceptionEnum;
import com.atung.exceptiom.WLTExceptionEnum;

/**
 * @since:
 * @author: wulitong
 * @create: 2020-08-17 17:53
 */
public class Result<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(T data) {
        this.data = data;
    }

    public static Result success() {
        return new Result(ResultStatus.SUCCESS.getStatus(), ResultStatus.SUCCESS.getResponsePhrase());
    }

    public static Result success(Object data) {
        return new Result(ResultStatus.SUCCESS.getStatus(), ResultStatus.SUCCESS.getResponsePhrase(), data);
    }

    public static Result error(int status) {
        return new Result(status, ResultStatus.getResponsePhrase(status));
    }

    public static Result error(int status, String msg) {
        return new Result(status, msg);
    }
    public static Result error(LcExceptionEnum ex){
        return new Result(ex.getCode(), ex.getMsg());
    }
}
